var url1;
var col = [];
var componen = 'master_'+type;

col[0] = new Array();

$(".datebox").datebox({
	formatter: formatDate,
	'setValue':'today'
});

if(type == "wilayah"){
	$('#prov').css({'display':'none'});
	$('#kab').css({'display':'none'});
	$('#kec').css({'display':'none'});
	$('#kel').css({'display':'none'});
	$('#wil	').css({'display':'none'});
 
	url1 = host+"master/getdata/wilayah";
    
	col[0][0] =   {field:'nama_wilayah',title:'Wilayah',width:200,halign:'center'};
	col[0][1] =   {field:'nama_provinsi',title:'Provinsi',width:200,halign:'center'};
    col[0][2] =   {field:'nama_kabupaten',title:'Kabupaten',width:200,halign:'center'};
    col[0][3] =   {field:'nama_kecamatan',title:'Kecamatan',width:200,halign:'center'};
    col[0][4] =   {field:'nama_kelurahan',title:'Kelurahan',width:200,halign:'center'};
    col[0][5] =   {field:'kode_pos',title:'Kode Pos',width:100,halign:'center', align:'right'};
	
	$("#category_"+type).change(function(){
		if($("#category_"+type).val()=='provinsi_cat'){
			$('#prov').css({'display':'inline'});
			$('#kab').css({'display':'none'});
			$('#kec').css({'display':'none'});
			$('#kel').css({'display':'none'});
			$('#wil	').css({'display':'none'});
		}else if($("#category_"+type).val()=='kabupaten_cat'){
			$('#prov').css({'display':'none'});
			$('#kab').css({'display':'inline'});
			$('#kec').css({'display':'none'});
			$('#kel').css({'display':'none'});
			$('#wil	').css({'display':'none'});
		}else if($("#category_"+type).val()=='kecamatan_cat'){
			$('#prov').css({'display':'none'});
			$('#kab').css({'display':'none'});
			$('#kec').css({'display':'inline'});
			$('#kel').css({'display':'none'});
			$('#wil	').css({'display':'none'});
		}else if($("#category_"+type).val()=='kelurahan_cat'){
			$('#prov').css({'display':'none'});
			$('#kab').css({'display':'none'});
			$('#kec').css({'display':'none'});
			$('#kel').css({'display':'inline'});
			$('#wil	').css({'display':'none'});
		}else if($("#category_"+type).val()=='nm_wilayah'){
			$('#prov').css({'display':'none'});
			$('#kab').css({'display':'none'});
			$('#kec').css({'display':'none'});
			$('#kel').css({'display':'none'});
			$('#wil	').css({'display':'inline'});
		}else if($("#category_"+type).val()==''){
			$('#prov').css({'display':'none'});
			$('#kab').css({'display':'none'});
			$('#kec').css({'display':'none'});
			$('#kel').css({'display':'none'});
			$('#wil	').css({'display':'none'});
		}
	});
	
} else if(type == "dealer") {
	$('#grup_dealer').css({'display':'none'});
	$('#nm_dealer').css({'display':'none'});
	
	url1 = host+"master/getdata/dealer";
	
	col[0][0] = {title:'IDENTITAS DEALER', colspan: 7,};
	col[1] 	  = new Array();				
	col[1][0] = {field:'nama_group_dealer',title:'Group Dealer',width:250,halign:'center'};
	col[1][1] = {field:'nama_dealer',title:'Nama Dealer',halign:'center',width:250,halign:'center'};
	col[1][2] = {field:'status_dealer',title:'Status Dealer',width:150,halign:'center',
					formatter: function(value,row,index){
						if(value == 'Y'){
							return "Dealer Aktif";
						}else{
							return "Dealer Tidak Aktif";
						}
					},
				};
	col[1][3] = {field:'kelas_dealer',title:'Kelas Dealer',width:200,halign:'center'};
	col[1][4] = {field:'no_telp',title:'No. Telp.',width:200,halign:'center',align:'right'};
	col[1][5] = {field:'no_fax',title:'Fax',width:200,halign:'center',align:'right'};
	col[1][6] = {field:'email',title:'Email',width:200,halign:'center'};
	
	col[0][1] = {title:'ALAMAT DEALER', colspan: 5};
	col[1][11] = {field:'alamat',title:'Alamat',width:300,halign:'center'};	
	col[1][7] = {field:'nama_provinsi',title:'Provinsi',width:200,halign:'center'};
	col[1][8] = {field:'nama_kabupaten',title:'Kabupaten',width:200,halign:'center'};
	col[1][9] = {field:'nama_kecamatan',title:'Kecamatan',width:200,halign:'center'};
	col[1][10] = {field:'nama_kelurahan',title:'Kelurahan',width:200,halign:'center'};
	
	col[0][2] = {title:'LEGAL ASPEK', colspan: 2};
	col[1][12] = {field:'no_npwp',title:'No. NPWP',width:250,halign:'center',align:'center'};
	col[1][13] = {field:'nama_tertera_npwp',title:'Nama NPWP',halign:'center',width:250,halign:'center'};
	
	$("#category_"+type).change(function(){
		if($("#category_"+type).val()=='grup_dealer'){
			$('#grup_dealer').css({'display':'inline'});
			$('#nm_dealer').css({'display':'none'});
		}else if($("#category_"+type).val()=='nama_dealer'){
			$('#grup_dealer').css({'display':'none'});
			$('#nm_dealer').css({'display':'inline'});
		}else if($("#category_"+type).val()==''){
			$('#grup_dealer').css({'display':'none'});
			$('#nm_dealer').css({'display':'none'});
		}
	});
	
	
} else if(type == "supplier") {
	$('#grup_supplier').css({'display':'none'});
	$('#nm_supplier').css({'display':'none'});
	
	url1 = host+"master/getdata/supplier";
	
	col[0][0] = {title:'IDENTITAS SUPPLIER', colspan: 6};
	col[1] 	  = new Array();				
	col[1][0] = {field:'nama_group_supplier',title:'Nama Group Supplier',width:250,halign:'center'};
	col[1][1] = {field:'nama_supplier',title:'Nama Supplier',width:250,halign:'center'};
	col[1][2] = {field:'no_telp',title:'Telepon',width:150,halign:'center',align:'right'};
	col[1][3] = {field:'no_fax',title:'Fax',width:150,halign:'center',align:'right'};
	col[1][4] =  {field:'email',title:'email',width:200,halign:'center'};
	col[1][5] =  {field:'status_supplier',title:'Status Supplier',width:200,halign:'center',
					formatter: function(value,row,index){
						if(value == 'Y'){
							return "Supplier Aktif";
						}else{
							return "Supplier Tidak Aktif";
						}
					}
				};
	col[0][1] = {title:'ALAMAT', colspan: 5};
	col[1][6] = {field:'alamat',title:'Provinsi',width:250,halign:'center'};
	col[1][7] = {field:'nama_provinsi',title:'Provinsi',width:200,halign:'center'};
	col[1][8] = {field:'nama_kabupaten',title:'Kabupaten',width:200,halign:'center'};
	col[1][9] = {field:'nama_kecamatan',title:'Kecamatan',width:200,halign:'center'};
	col[1][10] = {field:'nama_kelurahan',title:'Kelurahan',width:200,halign:'center'};
	
	col[0][2]  = {title:'LEGAL ASPEK', colspan: 4};
	col[1][11] = {field:'nama_akun_bank',title:'Nama Bank',width:200,halign:'center',};
	col[1][12] = {field:'no_akun_bank',title:'No. Account Bank',width:200,halign:'center',align:'right'};
	col[1][13] = {field:'no_npwp',title:'No. NPWP',width:200,halign:'center',align:'center'};
	col[1][14] = {field:'nama_tertera_npwp',title:'Nama NPWP',width:200,halign:'center'};
	
	$("#category_"+type).change(function(){
		if($("#category_"+type).val()=='group_supplier'){
			$('#grup_supplier').css({'display':'inline'});
			$('#nm_supplier').css({'display':'none'});
		}else if($("#category_"+type).val()=='nama_supplier'){
			$('#grup_supplier').css({'display':'none'});
			$('#nm_supplier').css({'display':'inline'});
		}else if($("#category_"+type).val()==''){
			$('#grup_supplier').css({'display':'none'});
			$('#nm_supplier').css({'display':'none'});
		}
	});

	
} else if(type == "customer") {
	$('#grup_customer').css({'display':'none'});
	$('#nm_customer').css({'display':'none'});
	
	url1 = host+"master/getdata/customer";
	
	col[0][0] = {title:'IDENTITAS CUSTOMER', colspan: 9};
	col[1] 	  = new Array();				
	col[1][0] = {field:'nama_group_customer',title:'Group Customer',width:250,halign:'center'};
	col[1][1] = {field:'nama_customer',title:'Nama Customer',width:250,halign:'center'};
	col[1][2] = {field:'tempat_lahir',title:'Tempat Lahir',width:200,halign:'center'};
	col[1][3] = {field:'tgl_lahir',title:'Tanggal Lahir',width:200,halign:'center',align:'center'};
	col[1][4] = {field:'nama_agama',title:'Agama',width:200,halign:'center'};
	col[1][5] = {field:'no_telp',title:'No. Telp.',width:150,halign:'center',align:'right'};
	col[1][6] = {field:'no_handphone',title:'No. HP.',width:150,halign:'center',align:'right'};
	col[1][7] = {field:'email',title:'Email',width:200,halign:'center'};
	col[1][8] = {field:'nama_di_bpkb',title:'Nama di BPKP',width:250,halign:'center'};
	
	col[0][1] = {title:'ALAMAT CUSTOMER', colspan: 3};
	col[1][9] = {field:'no_ktp',title:'No. KTP',width:200,halign:'center'};
	col[1][10] = {field:'alamat_ktp',title:'Alamat',width:350,halign:'center'};
	col[1][11] = {field:'status_tmp_tinggal',title:'Sts. Tempat Tinggal',width:250,halign:'center'};

	col[0][2] = {title:'PEKERJAAN', colspan: 5};
	col[1][12] = {field:'nama_jenis_pekerjaan',title:'Pekerjaan',width:200,halign:'center'};
	col[1][13] = {field:'no_npwp',title:'No. NPWP',width:300,halign:'center',align:'center'};
	col[1][14] = {field:'nama_tertera_npwp',title:'Nama NPWP',width:250,halign:'center'};
	col[1][15] = {field:'nama_usaha',title:'Nama Kantor/Usaha',width:250,halign:'center'};
	col[1][16] = {field:'alamat_kantor',title:'Alamat Kantor/Usaha',width:350,halign:'center'};
	
	col[0][3] = {title:'CONTACT PERSON', colspan: 2};
	col[1][17] = {field:'contact_person',title:'Contact Person',width:200,halign:'center'};
	col[1][18] =  {field:'no_hp_contact_person',title:'No. Telepon CP',width:200,halign:'center',align:'right'};
	
	$("#category_"+type).change(function(){
		if($("#category_"+type).val()=='group_customer'){
			$('#grup_customer').css({'display':'inline'});
			$('#nm_customer').css({'display':'none'});
		}else if($("#category_"+type).val()=='nama_customer'){
			$('#grup_customer').css({'display':'none'});
			$('#nm_customer').css({'display':'inline'});
		}else if($("#category_"+type).val()==''){
			$('#grup_customer').css({'display':'none'});
			$('#nm_customer').css({'display':'none'});
		}
	});
	
} else if(type == "gudang") {
	$('#dealer_gdg').css({'display':'none'});
	$('#nm_gdg').css({'display':'none'});
	
	url1 = host+"master/getdata/gudang";
	
	col[0][0] = {title:'IDENTITAS GUDANG', colspan: 8};
	col[1] 	  = new Array();				
	col[1][0] = {field:'nama_group_dealer',title:'Group Dealer',halign:'center',width:250,halign:'center'};
	col[1][1] = {field:'nama_dealer',title:'Nama Dealer',width:250,halign:'center'};
	col[1][2] = {field:'nama_divisi',title:'Divisi',width:250,halign:'center'};
	col[1][3] = {field:'nama_gudang',title:'Nama Gudang',width:250,halign:'center'};
	col[1][4] = {field:'nama_lokasi_gudang',title:'Lokasi Gudang',width:200,halign:'center'};
	col[1][5] = {field:'no_rak_gudang',title:'No. Rak Gudang',width:250,halign:'center',align:'right'};
	col[1][6] = {field:'keterangan',title:'Keterangan',width:300,halign:'center'};
	col[1][7] = {field:'status_gudang',title:'Status Gudang',width:200,halign:'center',
					formatter: function(value,row,index){
						if(value == 'Y'){
							return "Gudang Aktif";
						}else{
							return "Gudang Tidak Aktif";
						}
					}
			};

	$("#category_"+type).change(function(){
		if($("#category_"+type).val()=='dealer'){
			$('#dealer_gdg').css({'display':'inline'});
			$('#nm_gdg').css({'display':'none'});
		}else if($("#category_"+type).val()=='dealer_gdg'){
			$('#dealer_gdg').css({'display':'none'});
			$('#nm_gdg').css({'display':'inline'});
		}else if($("#category_"+type).val()==''){
			$('#dealer_gdg').css({'display':'none'});
			$('#nm_gdg').css({'display':'none'});
		}
	});
			
} else if(type == "karyawan") {
	$('#dealer').css({'display':'none'});
	$('#agama').css({'display':'none'});
	$('#divisi').css({'display':'none'});
	$('#karyawans').css({'display':'none'});
	
	url1 = host+"master/getdata/karyawan";
	
	col[0][0] = {title:'IDENTITAS KARYAWAN', colspan: 11};
	col[1] 	  = new Array();				
	col[1][0] = {field:'nama_karyawan',title:'Nama Karyawan',width:250,halign:'center'};
	col[1][1] = {field:'nik_karyawan',title:'NIK',width:250,halign:'center'};
	col[1][2] = {field:'jenis_kelamin',title:'Jenis Kelamin',width:150,halign:'center',
					formatter: function(value,row,index){
						if(value == 'L'){
							return "Laki-Laki";
						}else{
							return "Perempuan";
						}
					}	
				};
	col[1][3] = {field:'kewarganegaraan',title:'Kewarganegaraan',width:200,halign:'center',align:'center'};
	col[1][4] = {field:'tempat_lahir',title:'Tempat Lahir',width:200,halign:'center'};
	col[1][5] = {field:'tgl_lahir',title:'Tanggal Lahir',width:150,halign:'center',align:'center'};
	col[1][6] = {field:'nama_agama',title:'Agama',width:200,halign:'center'};
	col[1][7] = {field:'status_kawin',title:'Sts. Kawin',width:200,halign:'center',					
					formatter: function(value,row,index){
						if(value == 'M'){
							return "Menikah";
						}else if(value == 'BM'){
							return "Belum Menikah";
						}else if(value == 'JD'){
							return "Janda / Duda";
						}
					}	
				};
	col[1][8] = {field:'no_telp',title:'No.Telepon',width:200,halign:'center',align:'right'};
	col[1][9] = {field:'no_handphone',title:'No. Handphone',width:200,halign:'center',align:'right'};
	col[1][10] = {field:'email',title:'Email',width:200,halign:'center'};
	
	col[0][1] = {title:'JABATAN', colspan: 6};
	col[1][13] = {field:'nama_departemen',title:'Kode Pos',width:200,halign:'center'};
	col[1][11] = {field:'nama_dealer',title:'Dealer',width:250,halign:'center'};
	col[1][12] = {field:'nama_divisi',title:'Divisi',width:200,halign:'center'};
	col[1][14] = {field:'jabatan',title:'Jabatan',width:200,halign:'center'};
	col[1][15] = {field:'tgl_msk_kerja',title:'Tanggal Msk. Kerja',width:170,halign:'center',align:'center'};
	col[1][16] = {field:'status_karyawan',title:'Status Karyawan',width:300,halign:'center'};
	
	col[0][2] = {title:'PENDIDIKAN TERAKHIR', colspan: 3};
	col[1][17] = {field:'pendidikan_terakhir',title:'Pend. Terakhir',width:200,halign:'center'};
	col[1][18] = {field:'jurusan_pendidikan',title:'Jurusan',width:200,halign:'center'};
	col[1][19] = {field:'nama_tempat_pendidikan',title:'Nama Instansi',width:250,halign:'center'};
	
	col[0][3] = {title:'ALAMAT', colspan: 3};
	col[1][20] = {field:'no_ktp',title:'No. KTP',width:200,halign:'center'};
	col[1][21] = {field:'alamat_ktp',title:'Alamat KTP',width:300,halign:'center'};
	col[1][22] = {field:'alamat_karyawan',title:'Alamat Karyawan',width:300,halign:'center'};
	
	col[0][4] = {title:'CONTACT PERSON', colspan: 3};
	col[1][23] = {field:'contact_person',title:'Contact Person',width:200,halign:'center'};
	col[1][24] = {field:'hubungan_dng_karyawan',title:'Hub. Dgn. Karyawan',width:250,halign:'center'};
	col[1][25] = {field:'alamat_contact_person',title:'Alamat CP',width:300,halign:'center'};
	
	$("#category_"+type).change(function(){
		if($("#category_"+type).val()=='nm_dealer'){
			$('#dealer').css({'display':'inline'});
			$('#karyawans').css({'display':'none'});
			$('#agama').css({'display':'none'});
			$('#divisi').css({'display':'none'});
		}else if($("#category_"+type).val()=='nm_krywn'){
			$('#dealer').css({'display':'none'});
			$('#karyawans').css({'display':'inline'});
			$('#agama').css({'display':'none'});
			$('#divisi').css({'display':'none'});
		}else if($("#category_"+type).val()=='agma'){
			$('#dealer').css({'display':'none'});
			$('#karyawans').css({'display':'none'});
			$('#agama').css({'display':'inline'});
			$('#divisi').css({'display':'none'});
		}else if($("#category_"+type).val()=='dvs'){
			$('#dealer').css({'display':'none'});
			$('#karyawans').css({'display':'none'});
			$('#agama').css({'display':'none'});
			$('#divisi').css({'display':'inline'});
		}else if($("#category_"+type).val()==''){
			$('#dealer').css({'display':'none'});
			$('#karyawan').css({'display':'none'});
			$('#agama').css({'display':'none'});
			$('#divisi').css({'display':'none'});
		}
	});
} else if(type == "pihak") {
	$('#pihak_ketiga').css({'display':'none'});
	$('#agama_phk').css({'display':'none'});
	
	url1 = host+"master/getdata/pihak";
	
	col[0][0] = {title:'IDENTITAS PIHAK KETIGA', colspan: 10};
	col[1] 	  = new Array();				
	col[1][0] = {field:'nama_pihak3',title:'Nama Pihak Ketiga',width:250,halign:'center'};
	col[1][1] = {field:'jenis_kelamin',title:'Jenis Kelamin',width:200,halign:'center',
					formatter: function(value,row,index){
						if(value == 'L'){
							return "Laki-Laki";
						}else{
							return "Perempuan";
						}
					}		
				};
	col[1][2] = {field:'kewarganegaraan',title:'Kewarganegaraan',width:200,halign:'center'};
	col[1][3] = {field:'tempat_lahir',title:'Tempat Lahir',width:200,halign:'center'};
	col[1][4] = {field:'tgl_lahir',title:'Tanggal Lahir',width:150,halign:'center',align:'center'};
	col[1][5] = {field:'nama_agama',title:'Agama',width:200,halign:'center'};
	col[1][6] = {field:'status_kawin',title:'Sts. Kawin',width:200,halign:'center',
					formatter: function(value,row,index){
						if(value == 'M'){
							return "Menikah";
						}else if(value == 'BM'){
							return "Belum Menikah";
						}else if(value == 'JD'){
							return "Janda / Duda";
						}
					}	
				};
	col[1][7] = {field:'no_telepon',title:'No.Telepon',width:200,halign:'center'};
	col[1][8] = {field:'no_handphone',title:'No. Handphone',width:200,halign:'center'};
	col[1][9] = {field:'email',title:'Email',width:200,halign:'center'};
	
	col[0][1] = {title:'ALAMAT PIHAK KETIGA', colspan: 4};
	col[1][10] = {field:'no_ktp',title:'No. KTP',width:200,halign:'center'};
	col[1][11] = {field:'alamat_ktp',title:'Alamat KTP',width:300,halign:'center'};
	col[1][12] = {field:'alamat_pihak_ketiga',title:'Alamat Pihak Ketiga',width:300,halign:'center'};
	col[1][13] = {field:'status_tmp_tinggal',title:'Sts. Tempat Tinggal',width:150,halign:'center'};
	
	col[0][2] = {title:'CONTACT PERSON', colspan: 4};
	col[1][14] = {field:'contact_person',title:'Contact Person',width:200,halign:'center'};
	col[1][15] = {field:'hubungan_contact_person',title:'Hub. Dgn. Contact Person',width:250,halign:'center'};
	col[1][16] = {field:'alamat_contact_person',title:'Alamat CP',width:300,halign:'center'};
	col[1][17] = {field:'no_handphone_contact_person',title:'No. Ponsel CP',width:200,halign:'center'};
	
	$("#category_"+type).change(function(){
		if($("#category_"+type).val()=='nm_phk_ketiga'){
			$('#pihak_ketiga').css({'display':'inline'});
			$('#agama_phk').css({'display':'none'});
		}else if($("#category_"+type).val()=='agama_phak_ketiga'){
			$('#pihak_ketiga').css({'display':'none'});
			$('#agama_phk').css({'display':'inline'});
		}else if($("#category_"+type).val()==''){
			$('#pihak_ketiga').css({'display':'none'});
			$('#agama_phk').css({'display':'none'});
		}
	});
	
} else if(type == "kas") {
	$('#dealer_kass').css({'display':'none'});
	$('#nm_kas').css({'display':'none'});

	url1 = host+"master/getdata/kas";
	
	col[0][0] =   {field:'nama_group_dealer',title:'Group Dealer',width:200,halign:'center'};
	col[0][1] =   {field:'nama_dealer',title:'Dealer',width:200,halign:'center'};
    col[0][2] =   {field:'nama_kas',title:'Nama Kas',width:200,halign:'center'};
    col[0][3] =   {field:'no_account',title:'No. Account',width:200,halign:'center'};
    col[0][4] =   {field:'nama_account',title:'Nama Account',width:200,halign:'center'};
    col[0][5] =   {field:'nama_bank',title:'Nama Bank',width:200,halign:'center',};
	
	$("#category_"+type).change(function(){
		if($("#category_"+type).val()=='dealer_ks'){
			$('#dealer_kass').css({'display':'inline'});
			$('#nm_kas').css({'display':'none'});
		}else if($("#category_"+type).val()=='nama_ks'){
			$('#dealer_kass').css({'display':'none'});
			$('#nm_kas').css({'display':'inline'});
		}else if($("#category_"+type).val()==''){
			$('#dealer_kass').css({'display':'none'});
			$('#nm_kas').css({'display':'none'});
		}
	});
	
} else if(type == "aktiva") {
	$('#dealer_aktif').css({'display':'none'});
	$('#nm_aktiva').css({'display':'none'});

	url1 = host+"master/getdata/aktiva";
	
	col[0][0] =   {field:'nama_group_dealer',title:'Group Dealer',width:200,halign:'center'};
	col[0][1] =   {field:'nama_dealer',title:'Dealer',width:200,halign:'center'};
    col[0][2] =   {field:'nama_aktiva',title:'Nama Aktiva',width:200,halign:'center'};
    col[0][3] =   {field:'nilai_aktiva',title:'Nilai Aktiva',width:200,halign:'center'};
    col[0][4] =   {field:'tgl_beli',title:'Tanggal Pembelian',width:200,halign:'center',align:'center'};
    col[0][5] =   {field:'tgl_pakai',title:'Tanggal Pemakaian',width:200,halign:'center', align:'center'};
	
	$("#category_"+type).change(function(){
		if($("#category_"+type).val()=='dealer_akt'){
			$('#dealer_aktif').css({'display':'inline'});
			$('#nm_aktiva').css({'display':'none'});
		}else if($("#category_"+type).val()=='nama_akt'){
			$('#dealer_aktif').css({'display':'none'});
			$('#nm_aktiva').css({'display':'inline'});
		}else if($("#category_"+type).val()==''){
			$('#dealer_aktif').css({'display':'none'});
			$('#nm_aktiva').css({'display':'none'});
		}
	});
	
} else if(type == "warna") {
	judulwindowAdd = "Tambah Data Warna";
	judulwindowEdit = "Edit Data Warna";
	lebarjendelaForm = frmWidth-850;
	tinggijendelaFrom = frmHeight-100;
	tinggipanel = 100;
	url1 = host+"master/getdata/warna";
	
	col[0][0] = {field:'nama_warna',title:'Nama Warna',width:200};
	col[0][1] = {field:'status',title:'Status',width:200};
	
} else if(type == "motor") {
	judulwindowAdd = "Tambah Data Unit Motor";
	judulwindowEdit = "Edit Data Unit Motor";
	lebarjendelaForm = frmWidth-340;
	tinggijendelaFrom = frmHeight-100;
	tinggipanel = 550;	
	url1 = host+"master/getdata/motor";
	
	col[0][0] = {title:'IDENTITAS MOTOR', colspan: 4};
	col[1] 	  = new Array();				
	col[1][0] = {field:'nama_group_barang',title:'Group Barang',width:250};
	col[1][1] = {field:'kategori_barang',title:'Kategori Barang',width:200};
	col[1][2] = {field:'nama_motor',title:'Nama Motor',width:250};
	col[1][3] = {field:'jumlah_pilihan_warna',title:'Pilihan Warna',width:200};
	
	col[0][1] = {title:'MESIN', colspan: 4};
	col[1][4] = {field:'default_no_mesin',title:'No. Mesin',width:200};
	col[1][5] = {field:'type_mesin',title:'Type Mesin',width:200};
	col[1][6] = {field:'dimensi_mesin',title:'Dimensi Mesin',width:200};
	col[1][7] = {field:'dimensi_langkah',title:'Dimensi Langkah',width:200};
	col[1][8] = {field:'volume_cylinder',title:'Volume Cylinder',width:200};
	
	col[0][2] = {title:'RANGKA', colspan: 4};
	col[1][9] = {field:'default_no_kerangka',title:'No. Rangka',width:200};
	col[1][10] = {field:'type_rangka',title:'Type Rangka',width:200};
	col[1][11] = {field:'suspensi_depan',title:'Suspensi Depan',width:200};
	col[1][12] = {field:'suspensi_belakang',title:'Suspensi Belakang',width:200};
	
	col[0][3] = {title:'ELEKTRIK', colspan: 4};
	col[1][13] = {field:'baterai',title:'Baterai',width:200};
	col[1][14] = {field:'busi',title:'Busi',width:200};
	col[1][15] = {field:'sistem_pengapian',title:'Sistem Pengapian',width:200};
	col[1][16] = {field:'sekring',title:'Sekring',width:200};
	
	col[0][3] = {title:'DIMENSI', colspan: 4};
	col[1][17] = {field:'panjang_lebar_tinggi',title:'P x L x T',width:200};
	col[1][18] = {field:'kapasitas_tangki',title:'Kap. Tangki',width:200};
	col[1][19] = {field:'berat_isi',title:'Berat Isi',width:200};
	col[1][20] = {field:'berat_kosong',title:'Berat Kosong',width:200};
} else if(type == "sparepart") {
	judulwindowAdd = "Tambah Data Sparepart";
	judulwindowEdit = "Edit Data Sparepart";
	lebarjendelaForm = frmWidth-850;
	tinggijendelaFrom = frmHeight-100;
	tinggipanel = 190;	
	url1 = host+"master/getdata/sparepart";
	
	col[0][0] = {title:'IDENTITAS SPAREPART', colspan: 6};
	col[1] 	  = new Array();				
	col[1][0] = {field:'nama_group_barang',title:'Group Barang',width:250};
	col[1][1] = {field:'kategori_barang',title:'Kategori Barang',width:200};
	col[1][2] = {field:'nama_barang',title:'Nama SparePart',width:250};
	col[1][3] = {field:'merek_barang',title:'Merek',width:200};
	col[1][4] = {field:'satuan_barang',title:'Satuan Barang',width:200};
	col[1][5] = {field:'type_barang',title:'Type',width:200};
	
} else if(type == "generator") {
	judulwindowAdd = "Tambah Data Generator";
	judulwindowEdit = "Edit Data Generator";
	lebarjendelaForm = frmWidth-850;
	tinggijendelaFrom = frmHeight-100;
	tinggipanel = 400;	
	url1 = host+"master/getdata/generator";
	
	col[0][0] = {title:'IDENTITAS GENERATOR', colspan: 6};
	col[1] 	  = new Array();				
	col[1][0] = {field:'nama_group_barang',title:'Group Barang',width:250};
	col[1][1] = {field:'kategori_barang',title:'Kategori Barang',width:200};
	col[1][2] = {field:'nama_barang',title:'Nama Generator',width:250};
	col[1][3] = {field:'merek_barang',title:'Merek',width:200};
	col[1][4] = {field:'satuan_barang',title:'Satuan Barang',width:200};
	col[1][5] = {field:'type_generator',title:'Type',width:200};
	
} else if(type == "service") {
	judulwindowAdd = "Tambah Data Service";
	judulwindowEdit = "Edit Data Service";
	lebarjendelaForm = frmWidth-850;
	tinggijendelaFrom = frmHeight-100;
	tinggipanel = 200;	
	url1 = host+"master/getdata/service";
	
	col[0][0] = {field:'nama_group_service',title:'Group Service',width:250};
	col[0][1] = {field:'nama_kategori_service',title:'Kategori Barang',width:250};
	col[0][2] = {field:'jenis_service',title:'Jenis Service',width:250};
	col[0][3] = {field:'kartu_service',title:'Kartu Service',width:250};
	col[0][4] = {field:'ketentuan_jarak_tempuh',title:'Jarak Tempuh',width:200};
	col[0][5] = {field:'ketentuan_jangkawaktu_beli',title:'Jangka Waktu Pembelian',width:300};
} else if(type == "peralatan_service") {
	judulwindowAdd = "Tambah Data Peralatan Service (Toolkit)";
	judulwindowEdit = "Edit Data Peralatan Service (Toolkit)";
	lebarjendelaForm = frmWidth-850;
	tinggijendelaFrom = frmHeight-100;
	tinggipanel = 450;	
	url1 = host+"master/getdata/peralatan_service";
	
	col[0][0] = {title:'IDENTITAS TOOLKIT', colspan: 8};
	col[1] 	  = new Array();				
	col[1][0] = {field:'nama_group_barang',title:'Group Barang',width:250};
	col[1][1] = {field:'kategori_barang',title:'Kategori Barang',width:200};
	col[1][2] = {field:'nama_barang',title:'Nama Toolkit',width:250};
	col[1][3] = {field:'merek_barang',title:'Merek',width:200};
	col[1][4] = {field:'satuan_barang',title:'Satuan Barang',width:200};
	col[1][5] = {field:'type_barang',title:'Type',width:200};
	col[1][6] = {field:'fungsi_barang',title:'Fungsi',width:200};
	col[1][7] = {field:'jangka_waktu_pemakaian',title:'Jangka Waktu Pemakaian',width:300};
} else if(type == "barang_promosi"){
	judulwindowAdd = "Tambah Data Barang Promosi";
	judulwindowEdit = "Edit Data Barang Promosi";
	lebarjendelaForm = frmWidth-850;
	tinggijendelaFrom = frmHeight-100;
	tinggipanel = 500;	
	url1 = host+"master/getdata/barang_promosi";
	
	col[0][0] = {title:'IDENTITAS BARANG PROMOSI', colspan: 9};
	col[1] 	  = new Array();				
	col[1][0] = {field:'nama_group_barang',title:'Group Barang',width:250};
	col[1][1] = {field:'kategori_barang',title:'Kategori Barang',width:200};
	col[1][2] = {field:'nama_barang',title:'Nama Toolkit',width:250};
	col[1][3] = {field:'merek_barang',title:'Merek',width:200};
	col[1][4] = {field:'satuan_barang',title:'Satuan Barang',width:200};
	col[1][5] = {field:'type_barang',title:'Type',width:200};
	col[1][6] = {field:'fungsi_barang',title:'Fungsi',width:200};
	col[1][7] = {field:'jangka_waktu_pemakaian',title:'Jangka Waktu Pemakaian',width:300};
	col[1][8] = {field:'harga_beli',title:'Harga Beli',width:300};
// proses promosi
} else if(type == "proses_promosi_unit") {
	judulwindowAdd = "Tambah Data Proses Promosi Unit Motor";
	judulwindowEdit = "Edit Data Proses Promosi Unit Motor";
	lebarjendelaForm = frmWidth-850;
	tinggijendelaFrom = frmHeight-100;
	tinggipanel = 500;	
	url1 = host+"master/getdata/proses_promosi_unit";
	
	col[0][0] = {title:'PROSES PROMOSI UNIT MOTOR', colspan: 9};
	col[1] 	  = new Array();
	col[1][0] = {field:'no_memo',title:'Nomor Memo',width:200};				
	col[1][1] = {field:'nama_promosi',title:'Nama Promosi',width:250};
	col[1][2] = {field:'tgl_promosi',title:'Tanggal Promosi',width:200};
	col[1][3] = {field:'tgl_mulai',title:'Mulai Tanggal',width:250};
	col[1][4] = {field:'tgl_berakhir',title:'Berakhir Tanggal',width:200};
	
	col[1][5] = {field:'promosi_all_dealer',title:'All Dealer',width:200};
	col[1][6] = {field:'jenis_penjualan',title:'Jenis Penjualan',width:200,
					formatter: function(value,row,index){
						if(value == 'KD'){
							return "Kredit Dealer";
						}else if(value == 'T'){
							return "Tunai";
						}else if(value == 'KL'){
							return "Kredit Leasing";
						}else {
							return "N/A";
						}
					}	
				};
	col[1][7] = {field:'pembiayaan',title:'Pembiayaan',width:300};
} else if(type == "proses_promosi_service") {
	judulwindowAdd = "Tambah Data Proses Promosi Service";
	judulwindowEdit = "Edit Data Proses Promosi Service";
	lebarjendelaForm = frmWidth-850;
	tinggijendelaFrom = frmHeight-100;
	tinggipanel = 500;	
	url1 = host+"master/getdata/proses_promosi_service";
	
	col[0][0] = {title:'PROSES PROMOSI SERVICE', colspan: 9};
	col[1] 	  = new Array();
	col[1][0] = {field:'no_memo',title:'Nomor Memo',width:200};				
	col[1][1] = {field:'nama_promosi',title:'Nama Promosi',width:250};
	col[1][2] = {field:'tgl_promosi',title:'Tanggal Promosi',width:200};
	col[1][3] = {field:'tgl_mulai',title:'Mulai Tanggal',width:250};
	col[1][4] = {field:'tgl_berakhir',title:'Berakhir Tanggal',width:200};
	
	col[1][5] = {field:'nama_group_dealer',title:'Group Dealer',width:200};
	col[1][6] = {field:'nama_dealer',title:'Nama Dealer',width:200};
} else if(type == "proses_promosi_sparepart") {
	judulwindowAdd = "Tambah Data Proses Promosi Spare Part";
	judulwindowEdit = "Edit Data Proses Promosi Spare Part";
	lebarjendelaForm = frmWidth-850;
	tinggijendelaFrom = frmHeight-100;
	tinggipanel = 500;	
	url1 = host+"master/getdata/proses_promosi_sparepart";
	
	col[0][0] = {title:'PROSES PROMOSI SPAREPART', colspan: 9};
	col[1] 	  = new Array();
	col[1][0] = {field:'no_memo',title:'Nomor Memo',width:200};				
	col[1][1] = {field:'nama_promosi',title:'Nama Promosi',width:250};
	col[1][2] = {field:'tgl_promosi',title:'Tanggal Promosi',width:200};
	col[1][3] = {field:'tgl_mulai',title:'Mulai Tanggal',width:250};
	col[1][4] = {field:'tgl_berakhir',title:'Berakhir Tanggal',width:200};
} else if(type == "proses_bbn_unit") {
	judulwindowAdd = "Tambah Data Proses BBN Unit Motor";
	judulwindowEdit = "Edit Data Proses BBN Unit Motor";
	lebarjendelaForm = frmWidth-850;
	tinggijendelaFrom = frmHeight-100;
	tinggipanel = 500;	
	url1 = host+"master/getdata/proses_bbn_unit";
	
	col[0][0] = {title:'PROSES BBN UNIT', colspan: 9};
	col[1] 	  = new Array();
	col[1][0] = {field:'kategori_barang',title:'Kategori Barang',width:200};				
	col[1][1] = {field:'nama_barang',title:'Nama Barang',width:250};
	col[1][2] = {field:'tgl_mulai',title:'Mulai Tanggal',width:250};
	col[1][3] = {field:'tgl_berakhir',title:'Berakhir Tanggal',width:200};
} else if(type == "proses_pembiayaan_unit") {
	judulwindowAdd = "Tambah Data Proses Pembiayaan Unit Motor";
	judulwindowEdit = "Edit Data Proses Pembiayaan Unit Motor";
	lebarjendelaForm = frmWidth-850;
	tinggijendelaFrom = frmHeight-100;
	tinggipanel = 500;	
	url1 = host+"master/getdata/proses_pembiayaan_unit";
	
	col[0][0] = {title:'PROSES PEMBIAYAAN UNIT MOTOR', colspan: 9};
	col[1] 	  = new Array();
	col[1][0] = {field:'no_memo_proses_pembiayaan',title:'Nomor Surat',width:200};				
	col[1][1] = {field:'tgl_proses_pembiayaan',title:'Nama Promosi',width:250};
	col[1][2] = {field:'nama_group_supplier',title:'Group Supplier',width:200};
	col[1][3] = {field:'nama_supplier',title:'Nama Supplier',width:250};
	col[1][4] = {field:'id_jenis_support',title:'Jenis Support',width:200, 
					formatter: function(value,row,index){
						if(value == 'S'){
							return "SUbsidi";
						}else if(value == 'I'){
							return "Incentive";
						}else if(value == 'P'){
							return "Program Promo";
						}else {
							return "N/A";
						}
					}	
				};
} else if(type == "proses_service_ksg") {
	judulwindowAdd = "Tambah Data Proses Service KSG";
	judulwindowEdit = "Edit Data Proses Service KSG";
	lebarjendelaForm = frmWidth-850;
	tinggijendelaFrom = frmHeight-100;
	tinggipanel = 500;	
	url1 = host+"master/getdata/proses_service_ksg";
	
	col[0][0] = {title:'PROSES SERVICE KSG', colspan: 9};
	col[1] 	  = new Array();
	col[1][0] = {field:'kategori_barang',title:'Kategori Barang',width:200};				
	col[1][1] = {field:'nama_barang',title:'Nama Barang',width:250};
	col[1][2] = {field:'nama_supplier',title:'Nama Supplier',width:250};
	col[1][3] = {field:'alamat',title:'Alamat',width:200};
} else if (type == "kode_akun") {
	judulwindowAdd = "Tambah Data Kode Akun";
	judulwindowEdit = "Edit Data Kode Akun";
	lebarjendelaForm = frmWidth-850;
	tinggijendelaFrom = frmHeight-100;
	tinggipanel = 500;	
	url1 = host+"master/getdata/kode_akun";
	
	col[0][0] = {title:'KODE AKUN', colspan: 5};
	col[1] 	  = new Array();				
	col[1][0] = {field:'kode_akun',title:'Kode Akun',width:250};
	col[1][1] = {field:'nama_akun',title:'Nama Akun',width:200};
	col[1][2] = {field:'keterangan',title:'Keterangan',width:250};
	col[1][3] = {field:'tanggal_akun',title:'Tanggal',width:200};
	col[1][4] = {field:'saldo_awal',title:'Saldo Awal',width:200};
} else if (type == "akun_kas") {
	judulwindowAdd = "Tambah Data Akun Kas";
	judulwindowEdit = "Edit Data Akun Kas";
	lebarjendelaForm = frmWidth-850;
	tinggijendelaFrom = frmHeight-100;
	tinggipanel = 500;	
	url1 = host+"master/getdata/akun_kas";
	
	col[0][0] = {title:'DAFTAR AKUN KAS', colspan: 7};
	col[1] 	  = new Array();				
	col[1][0] = {field:'nama_group_dealer',title:'Nama Group Dealer',width:250};
	col[1][1] = {field:'nama_dealer',title:'Nama Dealer',width:200};
	col[1][2] = {field:'nama_kas',title:'Nama Kas',width:250};
	col[1][3] = {field:'type_akun',title:'Tipe Akun',width:200};
	col[1][4] = {field:'bagian_dari_akun',title:'Bagian Dari Akun',width:200};
	col[1][5] = {field:'bagian_dari_sub_akun',title:'Bagian Dari Sub Akun',width:200};
} else if (type == "akun_barang_jasa") {
	judulwindowAdd = "Tambah Data Akun Barang & Jasa";
	judulwindowEdit = "Edit Data Akun Barang & Jasa";
	lebarjendelaForm = frmWidth-850;
	tinggijendelaFrom = frmHeight-100;
	tinggipanel = 500;	
	url1 = host+"master/getdata/akun_barang_jasa";
	
	col[0][0] = {title:'DAFTAR AKUN BARANG DAN JASA', colspan: 7};
	col[1] 	  = new Array();				
	col[1][0] = {field:'id_group_barang',title:'Kode Group Barang',width:250};
	col[1][1] = {field:'nama_group_barang',title:'Group Barang',width:200};
	col[1][2] = {field:'id_kategori_barang',title:'Kode Kategori Barang',width:250};
	col[1][3] = {field:'kategori_barang',title:'Nama Kategori Barang',width:200};
	col[1][4] = {field:'nama_type_barang',title:'Type Barang',width:200};
	col[1][5] = {field:'akun_persediaan',title:'Akun Persediaan',width:200};
	//col[1][6] = {field:'kode_akun',title:'Kode Akun',width:200};
	//col[1][7] = {field:'nama_akun',title:'Nama Akun',width:200};
} else if (type == "akun_aktifa_tetap") {
	judulwindowAdd = "Tambah Data Akun Aktifa Tetap";
	judulwindowEdit = "Edit Data Akun Aktifa Tetap";
	lebarjendelaForm = frmWidth-850;
	tinggijendelaFrom = frmHeight-100;
	tinggipanel = 500;	
	url1 = host+"master/getdata/akun_aktifa_tetap";
	
	col[0][0] = {title:'DAFTAR AKUN AKTIFA TETAP', colspan: 7};
	col[1] 	  = new Array();				
	col[1][0] = {field:'id_group_dealer',title:'Kode Group Dealer',width:250};
	col[1][1] = {field:'nama_group_dealer',title:'Nama Group Dealer',width:200};
	col[1][2] = {field:'id_dealer',title:'Kode Dealer',width:250};
	col[1][3] = {field:'nama_dealer',title:'Nama Dealer',width:200};
	col[1][4] = {field:'nama_barang',title:'Nama Barang',width:200};
	col[1][5] = {field:'quantity',title:'Quantity',width:200};
	col[1][6] = {field:'satuan',title:'Satuan',width:200};
} else if (type == "akun_saldo") {
	judulwindowAdd = "Tambah Data Akun Saldo";
	judulwindowEdit = "Edit Data Akun Saldo";
	lebarjendelaForm = frmWidth-850;
	tinggijendelaFrom = frmHeight-100;
	tinggipanel = 500;	
	url1 = host+"master/getdata/kode_akun";
	
	col[0][0] = {title:'DAFTAR AKUN SALDO', colspan: 7};
	col[1] 	  = new Array();				
	col[1][0] = {field:'kode_group_barang',title:'Kode Group Dealer',width:250};
	col[1][1] = {field:'nama_group_barang',title:'Nama Group Dealer',width:200};
	col[1][2] = {field:'kode_kategori_barang',title:'Kode Dealer',width:250};
	col[1][3] = {field:'nama_kategori_barang',title:'Nama Dealer',width:200};
	col[1][4] = {field:'type_barang',title:'Nama Barang',width:200};
	col[1][5] = {field:'akun_persediaan',title:'Quantity',width:200};
	col[1][6] = {field:'kode_akun',title:'Satuan',width:200};
}


$("#"+type).datagrid({
    title:'',
    height:frmHeight-250,
    width:frmWidth-280,
	iconCls: 'table',
	rownumbers:true,
    fit:false,
    striped:false,
    pagination:true,
    sortable:true,
    url:url1,		
	nowrap: true,
    singleSelect:true,
	pagination:true,
	onLoadSuccess: function(data){
		if(data.total == 0){
			var $panel = $(this).datagrid('getPanel');
			var $info = '<div class="info-empty">Tidak Ada Data</div>';
			$($panel).find(".datagrid-view2 .datagrid-body").append($info);
			//$('#edit_data').linkbutton({disabled:true});
			//$('#delete_data').linkbutton({disabled:true});
		}
	},		
	toolbar:'#toolbar_'+type,		
    columns:col,
	/*columns:[
        kolom[type]
    ],*/       
});

function add(){
	tinggiregion = frmHeight-248;
	$('#'+componen).html('');
	$('#'+componen).addClass("loading");
	$.post('master/getform/add/'+type,{'tinggiregion':tinggiregion},function(resp){
		//windowForm(resp, judulwindowAdd, lebarjendelaForm, tinggijendelaForm);
		$('#'+componen).removeClass('loading')
		$('#'+componen).html(resp);
	});
}

function edit(){
	tinggiregion = frmHeight-248;
	var datamaster = $("#"+type).datagrid('getSelected');
	
	if(datamaster){
		$('#'+componen).html('');
		$('#'+componen).addClass("loading");
		$.post('master/getform/edit/'+type,{'tinggiregion':tinggiregion, 'id':datamaster.id},function(resp){
			//windowForm(resp, judulwindowAdd, lebarjendelaForm, tinggijendelaForm);
			$('#'+componen).removeClass('loading')
			$('#'+componen).html(resp);
		});
	}else{
		$.messager.alert('warning','Pilih Data Yang Akan Diedit!!','warning');
	}
}

function del() {
	var datamaster = $("#"+type).datagrid('getSelected');
	var dataval = { 'id':datamaster.id };
	
	if (type == 'sparepart' || type == 'generator' || 
		type == 'peralatan_service' || type == 'barang_promosi') {
			dataval = { 'id':datamaster.id, 'kdgambar':datamaster.kode_gambar };
		}
	
	if(datamaster){
		$.messager.confirm('Confirm','Anda yakin ingin menghapus data ini?', function(res) {
			if (res) {
				$('#'+componen).addClass("loading");
				$.post('master/removedata/'+type, dataval, function(resp){
					$('#'+componen).removeClass('loading');
					$("#"+type).datagrid('reload');
					if(resp == '0') {
						$.messager.alert('warning','Data gagal terhapus!!','warning');
					}
				});
			}
		});
	}else{
		$.messager.alert('warning','Pilih Data Yang Akan Dihapus!!','warning');
	}
}